a = int(input())
b = int(input())

for n in range(a,b+1):
    n1 = n
    m = 0
    while n1 !=0:
        m = m * 10 + n1 % 10
        n1 //= 10
    if m==n:
        continue
    isPrime = True
    for i in range(2,n):
        if n%i == 0:
            isPrime = False
            break
    if not isPrime:
        continue
    isPrime = True
    for i in range(2,m):
        if m%i == 0:
            isPrime = False
            break
    if not isPrime:
        continue
    print(n)

